import  {shoppingcarQuery} from  "@/model/shoppingcarModel"
export  default  {
    namespaced:true,
    state:{
        list:[],//购物车的数据
    },
    mutations:{
        clear(state){
            state.list = [];
        },
        initList(state,payload){//是一个集合
            state.list  = payload.map(item=>{
                item.checked=false;
                return  item;
            })
        }
    },
    actions:{
      async  initList({commit},params){
            let  res  = await  shoppingcarQuery(params);
            commit("initList",res.data);
        }
    },
    getters:{
        totalNum(state){
            let num = 0;
            if(state.list.length){
                num  = state.list.map(item=>item.buynum).reduce((a,b)=>a+b);
            }
            return  num;

        }

    }
}